import java.util.*;
public class Solution {
    public static void main(String[] args) {
        int[] nums={1,2,3,4,5,6,7,8};
        minWaitTime(nums,3);
//        new C().run();
    }
    public static void minWaitTime(int[] nums,int s) {
        int rs=0;
        List<List<Integer>> list = new ArrayList<>();
        Integer[] sum = new Integer[nums.length];
        for (int i = 0; i < nums.length; i++) {
            sum[i] = 0;
        }

        for (int i = 0; i < s; i++) {
            List<Integer> list1=new ArrayList<>();
            list1.add(nums[i]);
            list.add(list1);
        }
        for (int i = s; i < nums.length; i++) {
            list.sort(new Comparator<List<Integer>>() {
                @Override
                public int compare(List<Integer> t1, List<Integer> t2) {
                    return lookSum(t1)-lookSum(t2);
                }
            });
            list.get(0).add(nums[i]);
        }
        list.sort(new Comparator<List<Integer>>() {
            @Override
            public int compare(List<Integer> t1, List<Integer> t2) {
                return lookSum(t1)-lookSum(t2);
            }
        });
        System.out.println("接受服务的顺序是");
        for (int i = 0; i < list.size(); i++) {
            System.out.println("");
            for (Integer integer : list.get(i)) {
                System.out.print(integer+" ");
            }
        }
        for (int i = 0; i < list.size(); i++) {
            for (int j = 0; j < list.get(i).size()-1; j++) {
                rs += list.get(i).get(j+1)-list.get(i).get(j);
            }
        }
        System.out.println("");
        System.out.println("最小等待时间"+rs);
    }
    public static int lookSum(List<Integer> list){
        int sum=0;
        for (Integer integer : list) {
            sum += integer;
        }
        return sum;
    }

}

class C{
    int [] t= {2,5,3,3,1,4,4,5}; //顾客的等待时间
    int n=t.length;  //顾客人数
    int s=3;  //服务的点数
    int [][] shunxu=new int[s][n/3+1];
    void run() {
        int i,j;
        Arrays.sort(t);
        System.out.print("顾客的等待时间为：");
        for(i=0;i<n;i++) {
            System.out.print(t[i]+" ");
        }
        System.out.println();
        int ss=0;
        int count=0;
        for(i=0;i<n;i++) {
            shunxu[i%3][ss]=t[i];
            count++;
            if(count>2) {
                ss++;
                count=0;
            }
        }
        for(i=0;i<s;i++) {
            System.out.print("第"+(i+1)+"个点的服务顺序为：");
            for(j=0;j<n/3+1;j++) {
                if(shunxu[i][j]!=0)
                    System.out.print(shunxu[i][j]+" ");
            }
            System.out.println();
        }
        float [][] time=new float[s][10];  //等待时间表
        for(i=0;i<s;i++) {
            for(j=1;j<n/3+1;j++) {
                if(shunxu[i][j]!=0) {
                    if(j==1)
                        time[i][j]=shunxu[i][j-1];
                    else {
                        time[i][j]=shunxu[i][j-1]+time[i][j-1];
                    }
                }
            }
        }
        System.out.println("等待时间表为：");
        for(i=0;i<s;i++) {
            for(j=0;j<n/3+1;j++) {
                System.out.print(time[i][j]+" ");
            }
            System.out.println();
        }
        float time_all=0;      //总的等待时间
        for(i=0;i<s;i++) {
            for(j=0;j<n/3+1;j++) {
                time_all+=time[i][j];
            }
        }
        System.out.println("总的时间为："+time_all);
        float time_avg=time_all/n;
        System.out.println("等待的平均时间为："+time_avg);
    }
}